using DG.Tweening;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ElementEffector : MonoBehaviour
{
    private SpriteRenderer sr;
    public ResourceType resourceType;
    private ResourceType lastResourceType;
    private Vector3 begin_scale;
    private void OnMouseEnter()
    {
        this.GetComponent<SpriteRenderer>().color = this.GetComponent<SpriteRenderer>().color * 1.25f;
        this.transform.DOScale(begin_scale * 1.2f, 0.1f);
    }
    private void OnMouseExit()
    {
        this.GetComponent<SpriteRenderer>().color = this.GetComponent<SpriteRenderer>().color * 0.8f;
        this.transform.DOScale(begin_scale, 0.1f);
    }
    private void UpdateElementEffect()
    {
        if (resourceType == ResourceType.Trees)
        {
            sr.color = new Color(124.0f / 255, 92.0f / 255, 0);
            //sr.color = Color.red;
        }
        else if (resourceType == ResourceType.Herb)
        {
            sr.color = new Color(106.0f / 255, 0.8f, 18.0f / 255);
        }
        else if (resourceType == ResourceType.Mineral)
        {
            sr.color = new Color(0,0,0.8f);
        }
        else if (resourceType == ResourceType.Relic)
        {
            sr.color = Color.yellow;
        }
        else if (resourceType == ResourceType.None)
        {
            sr.color = new Color(0.8f, 0.8f, 0.8f);
        }
        lastResourceType=resourceType;
    }
    // Start is called before the first frame update
    void Start()
    {
        begin_scale = transform.localScale;
        sr = GetComponent<SpriteRenderer>();
        UpdateElementEffect();



    }
    
    // Update is called once per frame
    void Update()
    {
        if (resourceType != lastResourceType)
        {
            UpdateElementEffect();
            lastResourceType = resourceType;
        }
    }
}
